var isArrayLike = require("./15_isArrayLike");
var optimizeCb = require("./01_optimizeCb");
var keys = require("./07_keys");

function forEach(obj, iteratee, context) {
  iteratee = optimizeCb(iteratee, context);
  if (isArrayLike(obj)) {
    for (var i = 0; i < obj.length; ++i) {
      iteratee(obj[i], i, obj);
    }
  } else {
    var ks = keys(obj);
    for (var j = 0; j < ks.length; j++) {
      var currentKey = ks[j];
      iteratee(obj[currentKey], currentKey, obj);
    }
  }
}

module.exports = forEach;
